'use strict'


const { Sequelize,DataTypes } = require('sequelize');

// 方法 3: 分别传递参数 (其它数据库)
const db = new Sequelize('db1', 'root', 'root', {
    host: 'localhost',
    dialect: 'mysql'/* 选择 'mysql' | 'mariadb' | 'postgres' | 'mssql' 其一 */
});

// async function test(){
//     try {
//         await sequelize.authenticate();
//         console.log('Connection has been established successfully.');
//     } catch (error) {
//         console.error('Unable to connect to the database:', error);
//     }
// }

// test();

// (async () => {
//     try {
//         await sequelize.authenticate();
//         console.log('Connection has been established successfully.');
//     } catch (error) {
//         console.error('Unable to connect to the database:', error);
//     }
// })();

const User = db.define('user', {
    id: {
        type:DataTypes.INTEGER,
        primaryKey:true
    },
    username:DataTypes.STRING,
    password:DataTypes.STRING,
    avatar:DataTypes.STRING,
})

User.sync({force:true}).then(()=>{
    User.create({
        id:1,
        username:'admin',
        password:'113',
        avatar:''
    })
});